#include "ru_ntcreb_csir_libs_methods_SVCH_TractService.h"
#include <iostream>
#include "TractAlgorithmService.h"
#include "XMLBuilder.h"
#include "XMLParser.h"

extern "C"
	JNIEXPORT jstring JNICALL Java_ru_ntcreb_csir_libs_methods_SVCH_TractService_createTractArrayXML
	(JNIEnv *env, jobject obj, jstring inputTractXML){

		string inputTractXML_CPP = env->GetStringUTFChars(inputTractXML, NULL);
		shared_ptr<std::vector<TractDTO*>> tractArray = parseTractDTOXml(inputTractXML_CPP);
		map<double,double> tractMap = createTractArray(tractArray->at(0));
		char* resultXML = createTractArrayXML(tractMap);
		return env->NewStringUTF(resultXML);

}

extern "C"
	JNIEXPORT jstring JNICALL Java_ru_ntcreb_csir_libs_methods_SVCH_TractService_createParallelTwoTractsArrayXML
	(JNIEnv *env, jobject obj, jstring inputTractXML){

		string inputTractXML_CPP = env->GetStringUTFChars(inputTractXML, NULL);

		shared_ptr<std::vector<TractDTO*>> tractArray = parseTractDTOXml(inputTractXML_CPP);

		map<double,double> tractArray1 = createTractArray(tractArray->at(0));
		map<double,double> tractArray2 = createTractArray(tractArray->at(1));
		map<double,double> tractMap = createParallelTwoTractsArray(tractArray1,tractArray2);
		char* resultXML = createTractArrayXML(tractMap);
		return env->NewStringUTF(resultXML);
}


extern "C"
	JNIEXPORT jstring JNICALL Java_ru_ntcreb_csir_libs_methods_SVCH_TractService_createConsistentTwoTractsArrayXML
	(JNIEnv *env, jobject obj,jstring inputTractXML){

		string inputTractXML_CPP = env->GetStringUTFChars(inputTractXML, NULL);
		shared_ptr<std::vector<TractDTO*>> tractArray = parseTractDTOXml(inputTractXML_CPP);
		map<double,double> tractMap = createConsistentTwoTractsArray(*tractArray->at(0),*tractArray->at(1));
		char* resultXML = createParallelTwoTractsArrayXML(tractMap);
		return env->NewStringUTF(resultXML);
}
